package com.example.librarysystem.Service;
import com.example.librarysystem.enums.BookStatusEnum;
import com.example.librarysystem.mapper.BookMapper;
import com.example.librarysystem.mapper.UserInfoMapper;
import com.example.librarysystem.model.BookInfo;
import com.example.librarysystem.model.PageRequest;
import com.example.librarysystem.model.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookService {
    @Autowired
    private UserInfoMapper userInfoMapper;
    @Autowired
    private BookMapper bookMapper;
    public void addBook(BookInfo bookinfo) {
    bookMapper.addBook(bookinfo);
    }

    public List<BookInfo> getList() {
        return bookMapper.getallbook();
    }

    public ResponseResult<BookInfo> getListBypage(PageRequest pagerequest) {
        Integer count= bookMapper.count();
        List<BookInfo> bookInfos=bookMapper.getListByPage(pagerequest);
        for(BookInfo x:bookInfos){
           x.setStatusCN(BookStatusEnum.getStatusByCode(x.getStatus()).getDesc());
        }
        ResponseResult res=new ResponseResult<BookInfo>(count,bookInfos);
        return res;
    }

    public BookInfo queryBookById(Integer id) {
        return bookMapper.queryBookById(id);
    }

    public void updateBook(BookInfo bookInfo) {
        bookMapper.updateBook(bookInfo);
    }

    public Integer batchDelete(List<Integer> ids) {
        return bookMapper.batchDelete(ids);
    }
}
